#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

bool _st;

const int N=1000005,M=8005;
int n,m; 
int a[M],b[M];
ll c[M];
bool vis[80000];
bool check(int x)
{
	rep(i,2,x)
	{
		if (i*i>x) return 1;
		if (x%i==0) return 0;
	}
	return 1;
}
inline int dis(int x,int y)
{
	return max(abs(a[x]-a[y]),abs(b[x]-b[y]));
}
inline ll val(int x,int y)
{
	if (x>y) swap(x,y);
	return dis(x,y)*10000000000ll+x*100000ll+y;
}
vector<pii>g[80000];
vector<int>d[M];
int deg[M];
ll sum[M],f[M],G[M];
int ca[M],cb[M];
inline ll getnum(int x,int y)
{
	ll res=0;
	rep(i,1,n)
	{
		if (a[i]<=x&&b[i]<=y) res++;
	}
	return res;
}
inline ll getnum(int x1,int x2,int y1,int y2)
{
	return getnum(x2,y2)-getnum(x1-1,y2)-getnum(x2,y1-1)+getnum(x1-1,y1-1);
}
inline ll getc(int x,int y)
{
	ll res=0;
	rep(i,1,n)
	{
		if (a[i]<=x&&b[i]<=y) res+=c[i];
	}
	return res;
}
inline ll getc(int x1,int x2,int y1,int y2)
{
	return getc(x2,y2)-getc(x1-1,y2)-getc(x2,y1-1)+getc(x1-1,y1-1);
}

void work()
{
	cin >> n >> m;
	rep(i,1,n) cin >> a[i] >> b[i];
	rep(i,1,n) 
	{
		int x=a[i],y=b[i];
		a[i]=x+y,b[i]=x-y;
	}
	//rep(i,1,n) cout << a[i] << " " <<b[i] << endl;
	rep(i,1,n) ca[i]=a[i],cb[i]=b[i];
	sort(ca+1,ca+n+1),sort(cb+1,cb+n+1);
	rep(i,1,n) cin >> c[i];
	ll ans=0,cnt=0;
	rep(i,1,60000) g[i].clear();
	rep(i,1,n) rep(j,i+1,n)
	{
		if (vis[dis(i,j)]==0) continue;
		g[dis(i,j)].pb(mkp(i,j));
	}
	rep(i,1,60000)
	{
		if (SZ(g[i]))
		{
			vector<int>st;
			for (pii j:g[i]) st.pb(j.fi),st.pb(j.se);
			sort(st.begin(),st.end());
			st.erase(unique(st.begin(),st.end()),st.end());
			for (int j:st) d[j].clear(),deg[j]=0,sum[j]=0;
			for (pii j:g[i]) 
			{
				ans-=1ll*deg[j.fi]*c[j.se];
				ans-=1ll*deg[j.se]*c[j.fi];
				ans-=sum[j.fi]+sum[j.se];
				sum[j.fi]+=c[j.fi]+c[j.se];
				sum[j.se]+=c[j.fi]+c[j.se];
				deg[j.fi]++,deg[j.se]++;
			}
			for (pii j:g[i]) 
			{
				int x=j.fi,y=j.se;
				if (x>y) swap(x,y);
				if (deg[x]<=deg[y]) d[x].pb(y);
				else d[y].pb(x);
			}
			for (int j:st)
			{
				for (int k:d[j]) f[k]+=c[k]+c[j],G[k]++;
				for (int k:d[j]) for (int o:d[k]) ans-=2*(f[o]+G[o]*c[k]);
				for (int k:d[j]) f[k]-=c[k]+c[j],G[k]--;
			}
		}
	}
	rep(i,1,n) rep(j,i+1,n)
	{
		if (vis[dis(i,j)]==0) continue;
		//++cnt;
		//int lx=min(a[i],a[j]),rx=max(a[i],a[j]),ly=min(b[i],b[j]),ry=max(b[i],b[j]);
		ll num=0;
		//int D=dis(i,j);
		//num+=getnum(a[i]-D,a[i]+D,b[i]-D,b[i]+D);
		//cout<< i << " "<< j << " " << num << endl;
		//num+=getnum(a[j]-D,a[j]+D,b[j]-D,b[j]+D);
		//cout<< i << " "<< j << " " << num << endl;
		//num-=getnum(lx,rx,ly,ry);
		//cout << lx << " " << rx << " " << ly << " " << ry << endl;
		//cout<< i << " "<< j << " " << num << endl;
		//num-=getnum(lx+1,rx-1,ly+1,ry-1);
		//cout<< i << " "<< j << " " << num << endl;
		rep(k,1,n)
		{
			if (k==i||k==j) continue;
			ll x=dis(i,k),y=dis(j,k),z=dis(i,j);
			if ((x<=z&&z<=y)) ans+=c[k],num++;
			if (y<=z&&z<=x) ans+=c[k],num++;
		}
		//cout<< i << " "<< j << " " << num << endl;
		ans+=num*(c[i]+c[j]);
	}
	
	//cout << cnt << endl;
	cout << ans << endl;
}
bool _ed;

int main()
{
	freopen("chess.in","r",stdin);
	freopen("chess.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//cerr<< (&_st-&_ed)/1024.0/1024 << endl;
	vis[2]=1,vis[3]=1,vis[5]=1,vis[7]=1;
	for (int i=23;i<=60000;i+=20) if (check(i)) vis[i]=1;
	// rep(i,1,60000)
	// {
		// if (vis[i]) cout << i << endl;
	// }
	int T;
	cin >> T;
	while (T--) work();
	return 0;
}
